<?php include '../include/common.php'; ?>
<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=5">
	<title>用户登录</title>
	<meta name="description" content="<?php echo $config['description']; ?>">
	<meta name="keyword" content="<?php echo $config['keywords']; ?>">
	<!-- 样 式 文 件 -->
	<link rel="stylesheet" href="/component/pear/css/pear.css" />
	<link rel="stylesheet" href="/assets/css/other/login.css" />
</head>
<!-- 代 码 结 构 -->

<body background="/assets/images/background.svg" style="background-size: cover;">
	<form class="layui-form" action="javascript:void(0);">
		<div class="layui-form-item">
			<img class="logo" src="/logo.png" />
			<div class="title"><?php echo $config['sitename']; ?></div>
			<div class="desc">
				参加三钱杯比赛作品
			</div>
		</div>
		<div class="layui-form-item">
			<input type="text" placeholder="请输入你的账号" name="name" lay-verify="required" hover class="layui-input" />
		</div>
		<div class="layui-form-item">
			<input type="password" placeholder="请输入你的密码" name="pass" lay-verify="required" hover class="layui-input" />
		</div>

		<div class="layui-form-item">
			<div class="layui-row">
				<div class="layui-col-xs7">
					<div style="margin-right: 10px;">
						<input placeholder="输入右方图片中的字符" name="code" hover lay-verify="required" class="code layui-input layui-input-inline" />
					</div>
				</div>
				<div class="layui-col-xs5">
					<img src="code.php" class="codeImage" onclick="this.src='code.php?r='+Math.random();">
				</div>
			</div>
		</div>
		<div class="layui-form-item">
			<input type="checkbox" name="" title="记住密码" lay-skin="primary" checked>
		</div>
		<div class="layui-form-item">
			<button type="button" class="pear-btn pear-btn-success login" lay-submit lay-filter="login">
				登 入
			</button>
		</div>
	</form>
	<!-- 资 源 引 入 -->
	<script src="/component/layui/layui.js"></script>

	<script src="/component/pear/pear.js"></script>
	<script>
		layui.use(['form', 'jquery', 'button', 'popup'], function() {
			var $ = layui.jquery;
			var form = layui.form;
			var button = layui.button;
			var popup = layui.popup;

			// 登 录 提 交
			window.onkeypress = function(e) {
				if (e.keyCode == 13) {
					$('[lay-submit]').click();
				}
			}
			form.on('submit(login)', function(data) {

				/// 按钮加载动画
				var load = button.load({
					elem: '.login'
				});
				/// 登录
				$.ajax({
					url: './ajax.php?act=login',
					type: "POST",
					timeout: "5000",
					data: data.field,
					success: function(data) {
						load.stop();
						if (data.code == "200") {
							popup.success(data.msg, function() {
								window.location.href = "/user";
							});
						} else {
							popup.failure(data.msg);
							$('.codeImage').attr('src', 'code.php?' + Math.random());
							$('#code').val('');
						}
					},
					error: function(XMLResponse) {
						load.stop();
						popup.failure("登录异常");
					}
				});

				return false;
			});
		})
	</script>
</body>

</html>